package com.itfreer.data.db.service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.data.db.dao.DBRegistDao;
import com.itfreer.data.db.entity.DBRegistEntity;
import com.itfreer.data.db.service.DBRegistService;

/**
 * 数据注册服务
 * 
 * @author cai
 *
 */
@Component("dbRegistServiceImp")
public class DBRegistServiceImp implements DBRegistService {

	@Autowired
	private DBRegistDao dbrRegistDao;

	/**
	 * 获取实体列表
	 * 
	 * @param queryFields
	 *            查询字段
	 * @param where
	 *            查询条件
	 * @param order
	 *            排序条件
	 * @param pageSize
	 *            分页大小
	 * @param pageIndex
	 *            分页索引
	 * @return
	 */
	@Override
	public List<DBRegistEntity> getEntitys(String queryFields, Map<String, Object> where, Map<String, Integer> order,
			Integer pageSize, Integer pageIndex) {
		List<DBRegistEntity> resultList = dbrRegistDao.getEntitys(queryFields, where, order, pageSize, pageIndex);
		return resultList;
	}

	/**
	 * 获取当前条件下的数据行总数
	 * 
	 * @param where
	 *            查询条件
	 * @return
	 */
	@Override
	public Long getRowCounts(Map<String, Object> where) {
		return dbrRegistDao.getRowCounts(where);
	}

	/**
	 * 获取实体
	 * 
	 * @param guid
	 *            唯一值
	 * @return
	 */
	@Override
	public DBRegistEntity getEntity(String guid) {
		DBRegistEntity entity = dbrRegistDao.getEntity(guid);
		return entity;
	}

	/**
	 * 添加实体
	 * 
	 * @param entity
	 *            添加实体
	 * @return
	 */
	@Override
	public DBRegistEntity add(DBRegistEntity entity) {
		// 自动生成id的uuid码
		UUID uuid = UUID.randomUUID();
		entity.setId(uuid.toString());
		entity = dbrRegistDao.add(entity);

		return entity;
	}

	/**
	 * 更新实体
	 * 
	 * @param guid
	 *            唯一值
	 * @param entity
	 *            实体
	 * @return
	 */
	@Override
	public DBRegistEntity update(DBRegistEntity entity) {
		entity = dbrRegistDao.update(entity);
		return entity;
	}

	/**
	 * 删除实体
	 * 
	 * @param guid
	 *            唯一值
	 */
	@Override
	public void delete(String guid) {
		dbrRegistDao.delete(guid);
	}

	/**
	 * 指量删除实体
	 * 
	 * @param guid
	 *            唯一值集
	 */
	@Override
	public void deletes(String guids) {
		dbrRegistDao.deletes(guids);
	}
}